/*************************Copyright (c)*************************
 

**--------------------------File Info---------------------------

** File name:
** Last modified Date:

** Last Version:

** Descriptions:
**---------------------------------------------------------------

** Created by:		刘家辉 
** Created date:	2021/01/08

** Version:			V1.0
** Descriptions:	接受SIGIO以及SIGUSR1信号进入信号处理打印
** Notes:           gcc main.c -o mysignal
                    ./mysignal &
                    kill -SIGIO %1
                    kill -SIGUSR1 %1           
** Tips:                    
**---------------------------------------------------------------
*/

#include <signal.h>
#include <stdio.h>
#include <unistd.h>

// typedef void (*sighandler_t)(int);
void handler(int signum);

int main(void)
{
    // sighandler_t signal(int signum, sighandler_t handler);
    signal(SIGIO, handler);
    signal(SIGUSR1, handler);
    printf("%d  %d\n", SIGIO, SIGUSR1);

    while (1)
    {
        sleep(10);
    }
    
    return 0;
}

void handler(int signum)
{
    if (signum == SIGIO)
    {
        printf("SIGIO signal: %d <handler>\n", signum);
    }
    else if (signum == SIGUSR1)
    {
        printf("SIGUSR1 signal: %d <handler>\n", signum);
    }
    else
    {
        printf("error <handler>\n");
    }
}